package com.fantastic.web.controller.admin;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.result.ResultData;
import com.fantastic.mapper.zjs.SpecTypeMapper;
import com.fantastic.model.pojo.zjs.SpecType;
import com.fantastic.service.zjs.SpecTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/5/30 18:45
 * @description: 菜品规格类型表的请求控制器
 */
@RestController
@RequestMapping("/specType")
public class SpecTypeControllerAdmin {
    @Resource
    private SpecTypeService specTypeService;

    /**
     * 查询菜品规格类型表
     *
     * @param specType
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/listSpecType")
    public ResultData listSpecType(SpecType specType, @RequestParam(name="page",
            defaultValue = "1") int pageNum,
                                   @RequestParam(name="limit",defaultValue = "9999999") int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<SpecType> specTypes = specTypeService.listSpecType(specType);
        PageInfo<SpecType> pageInfo = new PageInfo<>(specTypes);
        return new ResultData(RespStatusInfo.OK, pageInfo);
    }

    /**
     * 获取单个菜品规格类型数据
     *
     * @param specTypeId
     * @return
     */
    @GetMapping("/getSpecType")
    public ResultData getSpecType(Integer specTypeId) {
        return new ResultData(RespStatusInfo.OK, specTypeService.getSpecType(specTypeId));
    }

    /**
     * 添加菜品规格类型数据
     *
     * @param specType
     * @return
     */
    @PostMapping("/insertSpecType")
    public ResultData insertSpecType(SpecType specType) {
        System.out.println(specType.getSpecTypeName());
        return new ResultData(RespStatusInfo.OK, specTypeService.insertSpecType(specType));
    }

    /**
     * 修改菜品规格类型数据
     *
     * @param specType
     * @return
     */
    @PostMapping("/updateSpecType")
    public ResultData updateSpecType(SpecType specType) {
        return new ResultData(RespStatusInfo.OK, specTypeService.updateSpecType(specType));
    }


    /**
     * 删除菜品规格类型数据
     *
     * @param specTypeId
     * @return
     */
    @PostMapping("/deleteSpecType")
    public ResultData deleteSpecType(Integer specTypeId) {
        return new ResultData(RespStatusInfo.OK, specTypeService.deleteSpecType(specTypeId));
    }

}
